# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=strfry
pkgver=0.9.6
pkgrel=0
pkgdesc="Nostr relay written in C++"
url="https://github.com/hoytech/strfry"
# x86, armhf, s390x: flatbuffers not available
arch="all !x86 !armhf !s390x"
license="GPL-3.0-or-later"
makedepends="
	flatbuffers-dev
	libsecp256k1-dev
	linux-headers
	lmdb-dev
	openssl-dev
	perl-regexp-grammars
	perl-template-toolkit
	perl-yaml
	zlib-dev
	zstd-dev
	"
install="$pkgname.pre-install"
subpackages="$pkgname-openrc"
_negentropy=bdd421c1fbf8ca6d4404597411674f09eb578eb5
_golpe=19ce1715c271eb5c1ae3dc9f422093e4afe6c5e7
_uwebsockets=fb7e8e60a7eb02f476b3b1785d810ac91cc685f2
_hoytech_cpp=73dcad058bfd96f9b2a0e7d5032fde441ad6a808
_config=ab8c38a2d00e58dd004fd71da7f0e70749993fc1
_rasgueadb=8cb6edd4aa6cdedfb6c2f8d34102b392bb1586fe
_lmdbxx=13851b3333a8840398ba0aa8b7d0febe661b08d5
_docopt_cpp=6f5de76970be94a6f1e4556d1716593100e285d2
_json=d73d01389660084a8dbedd44eb674da57f26aba6
_pegtl=9afe8a71920b9dadf309a503d734143e1ff78b3e
_loguru=644f60dca77de3b0f718a03d370c8ebdf5f97968
_parallel_hashmap=87ece91c6e4c457c5faac179dae6e11e2cd39b16
_templar=05554eea58a15d461e3385507c1c3fd1bfd05fa3
source="https://github.com/hoytech/strfry/archive/$pkgver/strfry-$pkgver.tar.gz
	negentropy-$_negentropy.tar.gz::https://github.com/hoytech/negentropy/archive/$_negentropy.tar.gz
	golpe-$_golpe.tar.gz::https://github.com/hoytech/golpe/archive/$_golpe.tar.gz
	uwebsockets-$_uwebsockets.tar.gz::https://github.com/hoytech/uWebSockets/archive/$_uwebsockets.tar.gz
	hoytech-cpp-$_hoytech_cpp.tar.gz::https://github.com/hoytech/hoytech-cpp/archive/$_hoytech_cpp.tar.gz
	taocpp-config-$_config.tar.gz::https://github.com/taocpp/config/archive/$_config.tar.gz
	rasgueadb-$_rasgueadb.tar.gz::https://github.com/hoytech/rasgueadb/archive/$_rasgueadb.tar.gz
	lmdbxx-$_lmdbxx.tar.gz::https://github.com/hoytech/lmdbxx/archive/$_lmdbxx.tar.gz
	docopt.cpp-$_docopt_cpp.tar.gz::https://github.com/docopt/docopt.cpp/archive/$_docopt_cpp.tar.gz
	taocpp-json-$_json.tar.gz::https://github.com/taocpp/json/archive/$_json.tar.gz
	taocpp-PEGTL-$_pegtl.tar.gz::https://github.com/taocpp/PEGTL/archive/$_pegtl.tar.gz
	loguru-$_loguru.tar.gz::https://github.com/emilk/loguru/archive/$_loguru.tar.gz
	parallel-hashmap-$_parallel_hashmap.tar.gz::https://github.com/greg7mdp/parallel-hashmap/archive/$_parallel_hashmap.tar.gz
	templar-$_templar.tar.gz::https://github.com/hoytech/templar/archive/$_templar.tar.gz
	update-double-conversion-targets_patch
	pre-build-pkgver_patch
	strfry-conf.patch
	strfry.initd
	strfry.confd
	"

prepare() {
	default_prepare

	rmdir -v external/negentropy
	ln -sv ../../negentropy-$_negentropy external/negentropy
	rmdir -v golpe
	ln -sv ../golpe-$_golpe golpe

	rmdir -v golpe/external/*
	ln -sv ../../uWebSockets-$_uwebsockets \
		golpe/external/uWebSockets
	ln -sv ../../hoytech-cpp-$_hoytech_cpp \
		golpe/external/hoytech-cpp
	ln -sv ../../config-$_config \
		golpe/external/config
	ln -sv ../../rasgueadb-$_rasgueadb \
		golpe/external/rasgueadb
	ln -sv ../../lmdbxx-$_lmdbxx \
		golpe/external/lmdbxx
	ln -sv ../../docopt.cpp-$_docopt_cpp \
		golpe/external/docopt.cpp
	ln -sv ../../json-$_json \
		golpe/external/json
	ln -sv ../../PEGTL-$_pegtl \
		golpe/external/PEGTL
	ln -sv ../../loguru-$_loguru \
		golpe/external/loguru
	ln -sv ../../parallel-hashmap-$_parallel_hashmap \
		golpe/external/parallel-hashmap
	ln -sv ../../templar-$_templar \
		golpe/external/templar

	# enable double-conversion for riscv64 and loongarch64
	patch golpe/external/json/include/tao/json/external/double.hpp \
		"$srcdir"/update-double-conversion-targets_patch

	# fix version string
	patch golpe/pre-build.pl "$srcdir"/pre-build-pkgver_patch
	sed -i "s|@PKGVER@|$pkgver|" golpe/pre-build.pl
}

build() {
	make
}

check() {
	./strfry --version
	./strfry --help
}

package() {
	install -Dvm755 strfry -t "$pkgdir"/usr/sbin/
	install -Dvm644 strfry.conf -t "$pkgdir"/etc/

	install -Dvm755 "$srcdir"/strfry.initd "$pkgdir"/etc/init.d/strfry
	install -Dvm644 "$srcdir"/strfry.confd "$pkgdir"/etc/conf.d/strfry
}

sha512sums="
aa8b4965c85596b7af754060f1e1d43cd3cc6e1bd1ad97241a6314bfda6f6ef6a6b47007aa3c549a78378f2419b0a8fa825b28be6126a2549219c41e3a0c6f1d  strfry-0.9.6.tar.gz
cbb8e18b6c48434618cda528c386908a9de80cdb85f807031710dcb3898b5b5f149823be4365c32d9656aa76dcaae69e8aa4e0fa18473c200846782ea87f3759  negentropy-bdd421c1fbf8ca6d4404597411674f09eb578eb5.tar.gz
5889931319907ae3bd01223693de4fcae89672c15a4113d51e1b8470fab49486c77af1ee78fa71942dd11cbd8d0b99b31f83ad7039b3951f4dba639b1a4e6d03  golpe-19ce1715c271eb5c1ae3dc9f422093e4afe6c5e7.tar.gz
3b4d8e1b5c55ce7eb147c309b42af09fa40eaa037828c11851c47cbe417fe280bd0b825fb677fc7a5b14021669971ed09dcffa371e663ea9b38f6ee3cc9d68a9  uwebsockets-fb7e8e60a7eb02f476b3b1785d810ac91cc685f2.tar.gz
dec902b5a3143113840dab26b060689f117e61e3896a9135d35e430f59fe367b752665274f6d936a95933858beec1927e14b5e93b5b3ad571fa7e20b839d14c0  hoytech-cpp-73dcad058bfd96f9b2a0e7d5032fde441ad6a808.tar.gz
0d09483540b5b118b29338149ff41b1a8f70a5e2462746f08aa100203c1815d5978eb818613d3771959a34c9c24bb94d46a22efd1e50ff8efdd7308ce049c634  taocpp-config-ab8c38a2d00e58dd004fd71da7f0e70749993fc1.tar.gz
d70ba9518d68e230d62aa8df228f6149e24ce24901fccadf0c731ac40a9f10d5fdcc2279b8f7281ee7103de69d67a164a3cb7967e55b710b7ea7b303f6c26602  rasgueadb-8cb6edd4aa6cdedfb6c2f8d34102b392bb1586fe.tar.gz
d29a8a3e0be4ca7e7b7de61f4012ad74356611238405d798ae7e3424b791e8f90a714a8e2fbb2f1ab2782e80b0b3485b2f1f0d044f67341499c1696b2a75d7a7  lmdbxx-13851b3333a8840398ba0aa8b7d0febe661b08d5.tar.gz
e4212711e88beee26258ef2644dd8577b6708dea47f05c6cce596c3198f659aa7c1e1d25eb57aae8b19d422c7bd7f628ba6db8f62ed1d3d28f171ab1db86db73  docopt.cpp-6f5de76970be94a6f1e4556d1716593100e285d2.tar.gz
46e1e73700c773c473d939ff435d2a942b0e67c7933575ef4a254d2dbd3dee68f1d57f6c0c66e84dd5be8f9a4102ae23fc5f77f4c4e78fb9c72fc5c28a313d24  taocpp-json-d73d01389660084a8dbedd44eb674da57f26aba6.tar.gz
879aeba0bb817657f60e8e74bf95f2bed6ed03f93e69cfda6d6ad5235719f70f177a9ba34d46c03c53c61bf07e676e943f186d46dd67c21827e63d21691a52fe  taocpp-PEGTL-9afe8a71920b9dadf309a503d734143e1ff78b3e.tar.gz
c937e6b359bdbc476758a3caaa32cd0ebd8ae443fa786887c811e8cc35c756a4d04ab247c7bd95f499e1345c0c2ca67716f4d8fadd84e963ca4fee941bde7073  loguru-644f60dca77de3b0f718a03d370c8ebdf5f97968.tar.gz
9cb3db26acb39395475aed1dac1188ab3e32359d529ef5b19164a2410ee986c4255f652099ab20f3afdff1ce5ac28b5efbf66887bbec39f6327115041375e919  parallel-hashmap-87ece91c6e4c457c5faac179dae6e11e2cd39b16.tar.gz
f97b8bf0b349a5a90eefdde008e0c185f0904d6b7b3deccec2f96a6ee4246e0e285cd157e74978255540ca369820c438a1a53039c12fd8638c1531a9ed58c88d  templar-05554eea58a15d461e3385507c1c3fd1bfd05fa3.tar.gz
32839300bfdfacf6286668370c74e77f39d6dd89076aa16a41c113c9257779a95a8fa6a6a4f5c7e6743cc0fbd6f4b8a5d62b16d22aa09abfc4a7a4c2c6ee3d73  update-double-conversion-targets_patch
0eb3137fbb994a7f74e1008b0e8e49e1c00f6d55d4807705bef5de84b9fa92e3de64378fab3d6ef37231f66e8f3bc477428787a2a241ac024b732fd58c1aa654  pre-build-pkgver_patch
a2daa5d7cb87e953667558b99d22a0f119cb83e4931b559c2d21b7e8e494707b3a6d4ecb2722de35386e60d07efb56bb8cda05746708b985bf97f153ea6981b4  strfry-conf.patch
b7d370863afecc96545ed9bfe5e5c796e23be4d473586129b610eb6bbd7b2a33c919ffdb3214d174d375ef60c089665065d27c9aef251ee4560dabe47e0c7b98  strfry.initd
e1819ab27702adb341cba3e5d9c3f4f0a4a840b8337870b1b78011691ab8d13f194e0a92bc53889adc0a1fbf92becac1ba41e47f4b82a300b4d9e77af4e4593e  strfry.confd
"
